package com.zjlanyun.erp.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Color;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.zjlanyun.erp.R;
import com.zjlanyun.erp.model.LeftMenuModel;

public class LeftMenuAdapter extends BaseAdapter {

	private ArrayList<LeftMenuModel> mList;
	private LayoutInflater mInflater;
	private Context mContext;
	
	public final class ListItemView{
        public TextView title;     
        public ImageView image;     
	}
	
	public LeftMenuAdapter(Context context, ArrayList<LeftMenuModel> mList){
		this.mInflater = LayoutInflater.from(context);
		this.mList = mList;
		this.mContext = context;
	}
	
	@Override
	public int getCount() {
		return mList.size();
	}

	@Override
	public Object getItem(int arg0) {
		return mList.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ListItemView listItemView = null;
		if(convertView == null){
			listItemView = new ListItemView();
			convertView = mInflater.inflate(R.layout.daily_left_menu_item, null);
			listItemView.title = (TextView) convertView.findViewById(R.id.title);
			listItemView.image = (ImageView) convertView.findViewById(R.id.image);
			convertView.setTag(listItemView);
		}else{
			listItemView = (ListItemView) convertView.getTag();
		}
		
		listItemView.title.setText(mList.get(position).getTitle());
		if(mList.get(position).getSelected()){
			convertView.setBackgroundColor(Color.WHITE);
			listItemView.title.setTextColor(Color.BLACK);
			listItemView.image.setImageResource(mList.get(position).getImage());
		}else{
			convertView.setBackgroundColor(ContextCompat.getColor(mContext, R.color.blue));
			listItemView.title.setTextColor(Color.WHITE);
			listItemView.image.setImageResource(mList.get(position).getImage_white());
		}
		
		return convertView;
	}

}
